﻿using NB.MGJ.Cache;
using NB.MGJ.Common.Helper;
using NB.MGJ.Common.Utility;
using NB.MGJ.FrameWork;
using NB.MGJ.Model;
using NB.MGJ.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace NB.MGJ.Common.Cache
{
    /// <summary>
    /// API 缓存类
    /// </summary>
    public static class UserHelperForApi
    {
        /// <summary>
        /// 获取用户信息
        /// </summary>
        public static LogOnUserModel GetUserInfo(string _token)
        {
            return CacheManager.Get<LogOnUserModel>("LoginUser" + _token);
        }

        /// <summary>
        /// 设置缓存信息
        /// </summary>
        public static LogOnUserModel SetUserToSession(L.EntityModel.V_User2 _user, string _token, string sign)
        {
            var _logonUser = new LogOnUserModel
            {
                UserID = _user.ID,
                EnterpriseId = _user.EnterpriseId,
                LoginName = _user.LoginName,
                RealName = _user.RealName,
                Modile = _user.Modile,
                EnterpriseName = _user.EnterpriseName,
                UserImg = _user.UserImg,
                Distributor = _user.Distributor,
                EndTime = _user.EndTime,
                Type = _user.Type,
                WXOpenId = _user.WXID,
                Sign = sign,
                ECode = _user.Code,
                RoleID = _user.roleNames,
                HeadId = _user.HeadId
            };
            CacheManager.Set("LoginUser" + _token, _logonUser, new TimeSpan(24, 0, 0));//过期时间  24H
            return _logonUser;
        }
    }
}
